﻿using System;
using System.Data;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using Telerik.Web.UI;
using KPIS.GERP.GHRMS.BLL;
using KPIS.GERP.GHRMS.IBLL;
using KPIS.GERP.GHRMS.MODEL;

namespace KPIS.GERP.GHRMS.APP.App_UI.Forms
{
    public partial class PS_RetirementDtls : System.Web.UI.Page
    {
        private SsMng ssMng = new SsMng();
        private IRetirementDetailBLL dtlsBLL = new RetirementDetailBLL();

        protected void Page_Load(object sender, EventArgs e)
        {
            lblRetireSeq.Text = Request.QueryString["Sequence"].ToString();

            if (!Page.IsPostBack)
            {
                LoadDataGrid(Int32.Parse(lblRetireSeq.Text.Trim()));
            }
        }
        public void LoadDataGrid(int Parent)
        {
            DataSet ds = dtlsBLL.LoadRetirementDetails((int?)null, Parent);
            DataTable dt = null;
            if (ds.Tables.Count > 0)
            {
                dt = ds.Tables[0];
                RadGrid1.DataSource = dt;
                RadGrid1.DataBind();
            }
        }
        protected void RadGrid1_ItemCommand(object source, Telerik.Web.UI.GridCommandEventArgs e)
        {
            if (e.CommandName == "DeleteAll")
            {
                GridItem[] items = RadGrid1.MasterTableView.GetItems(GridItemType.CommandItem);
                if (items.Length > 0)
                {
                    ((GridCommandItem)items[0]).FireCommandEvent("DeleteSelected", "");
                }
                else
                {
                    RadGrid1.Items[0].FireCommandEvent("DeleteSelected", "");
                }
            }
            else if (e.CommandName == "Delete")
            {
                int seq = Convert.ToInt32((e.Item as GridDataItem).OwnerTableView.DataKeyValues[e.Item.ItemIndex]["RETIRE_DTLS_SEQ"]);
                dtlsBLL.Delete(seq, ssMng.EmpSeqI);
            }

            LoadDataGrid(Int32.Parse(lblRetireSeq.Text.Trim()));
        }
    }
}
